import {Injectable} from "@angular/core";
import {Http} from '@angular/http';
import 'rxjs/add/operator/map';
import { environment } from "../../environments/environment"

@Injectable()
export class ManagerService{
    managers: string[];
    url: string;

    constructor(public http: Http){
        this.managers = ["crystal","22","fangni"];
        this.url = environment.host + environment.port;
    }

    getManagers() {
        // return this.http.get("http://jsonplaceholder.typicode.com/managers")
        return this.http.get(this.url + "/manager")
            .map(res => res.json());
    }

    findByManagerNo(managerNo) {
        return this.http.get(this.url + "/manager/findByManagerNo/" + managerNo)
            .map(res => res.json());
    }

    findByManagerName(managerName) {
        return this.http.get(this.url + "/manager/findByManagerName/" + managerName)
            .map(res => res.json());
    }

    findByManagerMail(managerMail) {
        return this.http.get(this.url + "/manager/findByManagerAddr/" + managerMail)
            .map(res => res.json());
    }

    findByManagerTel(managerTel) {
        return this.http.get(this.url + "/manager/findByManagerTel/" + managerTel)
            .map(res => res.json());
    }

    addManager(manager) {
        return this.http.post(this.url + "/manager/add", manager)
            .map(res => res.json());
    }

    deleteManager(id) {
        return this.http.get(this.url + "/manager/delete/" + id)
            .map(res => res.json());
    }

    openDev(id) {

    }

    closeDev(id) {

    }
}
